//
//  RelatedEquipmentCell.m
//  AILock
//
//  Created by 谭亚明 on 2020/7/7.
//  Copyright © 2020 tym. All rights reserved.
//

#import "RelatedEquipmentCell.h"
#import "UIImageView+YPImage.h"
@interface RelatedEquipmentCell()

@property(nonatomic,weak) UIImageView *headImage;
@property(nonatomic,weak) UILabel *typeLab;
@property(nonatomic,weak) UILabel *nameLab;
@property(nonatomic,weak) UILabel *descLab;
@property(nonatomic,weak) UIImageView *rightImage;
@end

@implementation RelatedEquipmentCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initUI];
    }
    return self;
}

-(void)setEquipMent:(EquipmentModel *)equipMent{
    [self.headImage yp_setImageUlr:[equipMent getEquipmentImage]];
    self.typeLab.text = equipMent.roomName;
    self.nameLab.text = equipMent.equipmentName;
    self.descLab.text = @"";
    if (equipMent.isSelected) {
        [self.rightImage setImage:[UIImage imageNamed:@"icon_home12"]];
    }else{
        [self.rightImage setImage:[UIImage imageNamed:@"icon_home13"]];
    }
}

-(void)initUI{
 
    UIImageView *head = [[UIImageView alloc] init];
    head.backgroundColor = rgba(246, 246, 246);
    head.contentMode = UIViewContentModeScaleAspectFit;
    [self.contentView addSubview:head];
    self.headImage = head;
    
    TYMLabel *typeLab = [TYMLabel lb_text:@"公共" font:Font_Regular(10) color:[UIColor whiteColor]];
    typeLab.textAlignment = NSTextAlignmentCenter;
    typeLab.layer.masksToBounds = YES;
    typeLab.layer.cornerRadius = 2;
    [self.contentView addSubview:typeLab];
    typeLab.backgroundColor = rgba(76, 132, 255);
    self.typeLab = typeLab;
    
    TYMLabel *lab = [TYMLabel lb_text:@"sdfsfs" font:Font_Medium(15) color:rgba(74, 74, 74)];
    [self.contentView addSubview:lab];
    self.nameLab  = lab;
    
    TYMLabel *descLab = [TYMLabel lb_text:@"描述" font:Font_Regular(15) color:rgba(155, 155, 155)];
    [self.contentView addSubview:descLab];
    self.descLab  = descLab;
    
    UIImageView *image = [[UIImageView alloc] init];
    image.contentMode = UIViewContentModeScaleAspectFill;
    [self.contentView addSubview:image];
    self.rightImage = image;
    
    [self.headImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(CGSizeMake(98, 84));
        make.centerY.equalTo(self.contentView);
        make.left.mas_equalTo(0);
    }];
    
    [self.typeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.headImage.mas_right).offset(20);
        make.height.mas_equalTo(17);
        make.top.mas_equalTo(20);
    }];
    
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.typeLab.mas_right).offset(10);
        make.centerY.equalTo(self.typeLab);
    }];
    
    [self.descLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.typeLab.mas_left);
        make.top.mas_equalTo(self.typeLab.mas_bottom).offset(11);
    }];
    
    [self.rightImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.headImage);
        make.width.height.equalTo(@(20));
        make.right.mas_equalTo(@(-15));
    }];
}

+(NSString*)identifier{
    return @"RelatedEquipmentCell";
}

+(CGFloat)cellForHeight{
    return 84;
}

@end
